﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web
{
    public partial class SelCardRecord : BasePage
    {
        protected string UserLoginName = "";//当前登录用户
        public StringBuilder strCardRecord = new StringBuilder();//卡详细流水
        public string CharXVal;
        public string CharSeries;
        public string CharYVal;
        protected void Page_Load(object sender, EventArgs e)                                        
        {
            UserLoginName = LoggedUser.USERNAME;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            lb_Message.Visible = false;//消息提示
            string strWhere = "";//查询条件
            if (txt_CardNO.Text.Trim().Length > 0)//卡号
                strWhere += " and cardno='" + txt_CardNO.Text.Trim() + "'";
            if (txt_cardhno.Text.Trim().Length>0)//盒号
                strWhere += " and cardhno='" + txt_cardhno.Text.Trim() + "'";
            if (txt_boxno.Text.Trim().Length>0)//箱号
                strWhere += " and boxno='" + txt_boxno.Text.Trim() + "'";
            if (strWhere == "")
            {
                lb_Message.Visible = true;
                return;
            }
            //根据登录用户获取所有未审批信息
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult("select * from v_cardrecord where 1=1 " + strWhere + " and rownum <=1");//查询一条数据
            strCardRecord.Clear();//清空字符串
            if (dt != null && dt.Rows.Count > 0)
            {
                if (txt_CardNO.Text.Trim().Length > 0)//卡号
                {
                    strCardRecord.Append("卡号:<b>" + dt.Rows[0]["cardno"].ToString() + "</b><br/>");
                    strCardRecord.Append("盒号:<b>" + dt.Rows[0]["cardhno"].ToString() + "</b><br/>");
                }
                else if (txt_CardNO.Text.Trim().Length == 0 && txt_cardhno.Text.Trim().Length > 0)
                {
                    strCardRecord.Append("盒号:<b>" + dt.Rows[0]["cardhno"].ToString() + "</b><br/>");
                }
                //if (txt_cardhno.Text.Trim().Length > 0)//盒号
                strCardRecord.Append("箱号:<b>" + dt.Rows[0]["boxno"].ToString() + "</b><br/>");
                if (dt.Rows[0]["bkrukuno"]!= null && dt.Rows[0]["bkrukuno"].ToString() != "")
                {
                    strCardRecord.Append("白卡入库单编号:<b>" + dt.Rows[0]["bkrukuno"].ToString() + "</b>&nbsp;&nbsp;白卡入库单时间:<b>" + DateTime.Parse(dt.Rows[0]["bkrukusj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["bkrukuno"] != null && dt.Rows[0]["bkchukuno"].ToString() != "")
                {
                    strCardRecord.Append("白卡出库单编号:<b>" + dt.Rows[0]["bkchukuno"].ToString() + "</b>&nbsp;&nbsp;白卡出库单时间:<b>" + DateTime.Parse(dt.Rows[0]["bkchukusj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["bcprukuno"] != null && dt.Rows[0]["bcprukuno"].ToString() != "")
                {
                    strCardRecord.Append("成品入库单编号:<b>" + dt.Rows[0]["bcprukuno"].ToString() + "</b>&nbsp;&nbsp;半成品入库单时间:<b>" + DateTime.Parse(dt.Rows[0]["bcprukusj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["cpchuno"] != null && dt.Rows[0]["cpchuno"].ToString() != "")
                {
                    strCardRecord.Append("成品出库单编号:<b>" + dt.Rows[0]["cpchuno"].ToString() + "</b>&nbsp;&nbsp;成品出库单时间:<b>" + DateTime.Parse(dt.Rows[0]["cpchusj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["cpfafangno"] != null && dt.Rows[0]["cpfafangno"].ToString() != "")
                {
                    strCardRecord.Append("成品发放单编号:<b>" + dt.Rows[0]["cpfafangno"].ToString() + "</b>&nbsp;&nbsp;成品发放单时间:<b>" + DateTime.Parse(dt.Rows[0]["cpfafangsj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["dbrkno"] != null && dt.Rows[0]["dbrkno"].ToString() != "")
                {
                    strCardRecord.Append("调拨入库单编号:<b>" + dt.Rows[0]["dbrkno"].ToString() + "</b>&nbsp;&nbsp;调拨入库单时间:<b>" + DateTime.Parse(dt.Rows[0]["dbrksj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["dbckno"] != null && dt.Rows[0]["dbckno"].ToString() != "")
                {
                    strCardRecord.Append("调拨出库单编号:<b>" + dt.Rows[0]["dbckno"].ToString() + "</b> 调拨出库单时间:<b>" + DateTime.Parse(dt.Rows[0]["dbcksj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["zhikahkno"] != null && dt.Rows[0]["zhikahkno"].ToString() != "")
                {
                    strCardRecord.Append("制卡坏卡单编号:<b>" + dt.Rows[0]["zhikahkno"].ToString() + "</b>&nbsp;&nbsp;制卡坏卡时间:<b>" + DateTime.Parse(dt.Rows[0]["zhikahksj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["wswtkno"] != null && dt.Rows[0]["wswtkno"].ToString() != "")
                {
                    strCardRecord.Append("未售问题卡单编号:<b>" + dt.Rows[0]["wswtkno"].ToString() + "</b>&nbsp;&nbsp;未售问题卡时间:<b>" + DateTime.Parse(dt.Rows[0]["wswtksj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
                if (dt.Rows[0]["bfrkno"] != null && dt.Rows[0]["bfrkno"].ToString() != "")
                {
                    strCardRecord.Append("报废入库单编号:<b>" + dt.Rows[0]["bfrkno"].ToString() + "</b>&nbsp;&nbsp;报废入库时间:<b>" + DateTime.Parse(dt.Rows[0]["bfrksj"].ToString()).ToString("yyyy-MM-dd") + "</b><br/>");
                }
            }
            else
            {
                lb_Message.Visible = true;
            }
        }
    }
}